[
    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json; charset=UTF-8';
        let LANG = this.LANG();
        let $DATA = Object.assign({},this.$DATA);
       
        let $Security = await Mem.Get("session/"+kuo.sessionid);
        if(! $Security ){
            $Security ={ adminid: 0};
        }
        if(typeof($Security['adminid']) == "undefined" ){
            $Security['adminid'] = 0;
        }
        if($Security['adminid'] < 1){
            $DATA.code = 99;
            $DATA.msg = "Go Login";
            Context.body =JSON.stringify($DATA);
            return ;
        }
        let fan = await Mode("admin").Loginok(kuo,$Security);
        if(fan){
            $DATA.code = fan;
            $DATA.msg = "Error " + kuo.sessionid;
            if($Security['adminid'] > 0){
                let $hash = 'safetoken/'+$Security['adminid'];
                $DATA.token = Mode("Tools").Uuid();
                Mem.Set($hash,$DATA.token);
            }
            Context.body = JSON.stringify($DATA);
            return ;
        }

    
       
        kuo.adminid = $Security['adminid'];
        let $hash = 'safetoken/'+kuo.adminid;
        $DATA.token = Mode("Tools").Uuid();
        Mem.Set($hash,$DATA.token);
        let  $kongzhi = kuo.Path[1]?kuo.Path[1]:"get";
        let  $db = await db('host_list');
        let  $_GET = kuo.get;
        let  $_POST = kuo.post;
        let  $chushi = true; 
        let  $features = await Kuoplus(kuo.class);
       
        if($kongzhi == 'get'){

            let $page = Mode("Tools").Int($_GET['page']?$_GET['page']:1);
            let $limitx  =  Mode("Tools").Int($_GET['limit']?$_GET['limit']:10);
            if($limitx < 10 ){
                $limitx = 10;
            }else if($limitx > 100 ){
                $limitx = 100;
            }
            let $where ={};

            if(isset($_GET['name']) && $_GET['name'] !=""){
                $where['name LIKE']= '%'+$_GET['name']+'%';
            }

           
            let $data  = await $db.Where($where).Limit($limitx,$page).Order("id desc").Select();
            let $total = await $db.Where($where).Total();
            if(!$data){
                $data= [];
            }
            $DATA.code = 0;
            $DATA.count = $total;
            if($page == 1 && $chushi){
              
            }
    
            $DATA.data = $data;
    
    
    
        }else if($kongzhi == 'put'){
            let $id = Mode("Tools").Int($_POST['id']?$_POST['id']:0);
            let $data = await $db.Where({id: $id}).Find();
            if(!$data){
                $DATA.code = -1;
                $DATA.msg = LANG.admin_id_no;
                Context.body = JSON.stringify($DATA);
                return ;
            }

            $_POST['host']= implode(',',$_POST['host']);
            $_POST['shell']= implode(',',$_POST['shell']);
            $_POST['proxy']= implode(',',$_POST['proxy']);
            $_POST['atime']=  Mode("Tools").Time();
            let $fan = await $db.Where({id: $id}).Update($_POST);
            
            if($fan){

                await Kuolog('adminlog',kuo.adminid,3,{'yuan':$data,'data':$_POST},kuo.func_,kuo.class,kuo.ip);
                $DATA.data = $_POST;
                $DATA.code =1;
                $DATA.msg = LANG.put_ok;
                this.AddHost($id);
            }else{
                $DATA.code =-1;
                $DATA.msg = LANG.put_no;
            }
    
            
        }else if($kongzhi == 'add'){
    
            $_POST['host']= implode(',',$_POST['host']);
            $_POST['shell']= implode(',',$_POST['shell']);
            $_POST['proxy']= implode(',',$_POST['proxy']);
            $_POST['atime']=  Mode("Tools").Time();
            let $fan =await $db.Insert($_POST);
            
            if($fan){
                $DATA.code = 1;
                $DATA.msg = LANG.add_ok;
                this.AddHost($fan);
                await Kuolog('adminlog',kuo.adminid,4, $_POST ,kuo.func_,kuo.class,kuo.ip);
            }else{
                $DATA.code = -1;
                $DATA.msg = LANG.add_no;
            }

        }else if($kongzhi == 'del'){
    
            let $id = Mode("Tools").Int($_POST['id']?$_POST['id']:0);
            let $data = await $db.Where({id: $id}).Find();
    
            if(!$data){
                $DATA.code = -1;
                $DATA.msg = LANG.admin_id_no;
                Context.body = JSON.stringify($DATA);
                return ;
            }
            
            let type =$_POST['type']?$_POST['type']:"";
            if(type != ""){
               
                if(type == "daili"){
                    $DATA.code = 1;
                    this.Jiepart($id);
                }else if(type == "jiaoben"){
                    $DATA.code = 1;
                    this.Jieshell($id);
                
                }else if(type == "jieya"){
                    
                    if($data['zip'] == ""){
                        $DATA.code = -1;
                        $DATA.msg= LANG.zip_no;
                    }else{
                        $DATA.code = 1;
                        $data['zip'] = Mode("Tools").Xss(Mode("Tools").GUoLV($data['zip']));
                        $data.file = Trim( Mode("Tools").GUoLV($data.file),'/');
                        if($data.file != ""){
                            let ZIP =  DIR+"www"+$data['zip'];
                            let lujing = DIR+"HOST/"+$data.file+'/';
                            let zipfile ="unzip -o "+ZIP+" -d "+lujing+"";
                            var exec = require('child_process').exec;
                            exec(zipfile);
                            this.Jiepart($id);
                            await $db.Where({id: $id}).Update({zip:""});
                            try {
                                FS.unlinkSync(ZIP);  
                            } catch (error) {}
                        }
                    }
                }

                Context.body = JSON.stringify($DATA);
                return ;
            }
    
            let $fan = await $db.Where({id: $id}).Delete();
            if($fan){

                this.Xieguild();
                this.Jiepart($id);
                this.Jieshell($id);
                await  Kuolog('adminlog',kuo.adminid,5, $data ,kuo.func_,kuo.class,kuo.ip);
                $DATA.code = 1;
                $DATA.msg = LANG.del_ok;
            }else{
                $DATA.code = -1;
                $DATA.msg = LANG.del_no;
            }
        }

        Context.body = json_encode($DATA);
    }
]